/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elsimulatorjava;

import java.util.ArrayList;

/**
 *
 * @author corey
 */
public class Floor {
   // public Signal2<Integer, Integer> numberOfPeopleChanged = new Signal2<Integer, Integer>();
    // The name, door, and number of the floor.
    private static short floorCount = 0;
    private short index;
    private String name;
    
    private boolean upLock;
    private boolean downLock;
    
    // People
    private ArrayList<Person> people = new ArrayList<Person>();;
    
    //Buttons 
    private Boolean upButtonPushed;
    private Boolean downButtonPushed;

    
    // Constructors
    public Floor(String fN) {
        upButtonPushed = false;
        downButtonPushed = false;
        upLock = false;
        downLock = false;
        index = floorCount++;
        name = fN;
        people = new ArrayList<Person>();
    }

    // Functions
    protected void addPerson(Person p) {
        people.add(p);
        if (p.getFloorDest() > index) {
            upButtonPushed = true;
        }
        else if (p.getFloorDest() < index){
            downButtonPushed = true;
        }
    }
    
    protected void removePerson(Person p) {
        people.remove(p);
    }
    

    
    // Getter and setters
    protected ArrayList<Person> getPeople() {
        return this.people;
    }
    
    protected ArrayList<Person> getPeopleWaiting() {
        ArrayList<Person> waiting = new ArrayList<Person>();
        for (Person person : people){
            if (!person.isFinished()){
                waiting.add(person);
            }
        }
        return waiting;
    }
    
    protected ArrayList<Person> getPeopleFinished() {
        ArrayList<Person> finished = new ArrayList<Person>();
        for (Person person : people){
            if (person.isFinished()){
                finished.add(person);
            }
        }
        return finished;
    }

    protected void setName(String name) {
        this.name = name;
    }

    protected Boolean isUpButtonOn() {
        return upButtonPushed;
    }
    protected Boolean isDownButtonOn() {
        return downButtonPushed;
    }

    protected void setUpButtonOn(Boolean pushed) {
        upButtonPushed = pushed;
    }

    protected void setDownButtonOn(Boolean pushed) {
        downButtonPushed = pushed;
    }
    
    static void resetCounter(){
        floorCount = 0;
    }

    protected short getIndex() {
        return index;
    }
    
    protected void setUpLock(boolean lock) {
        this.upLock = lock;
    }
    
    protected boolean isUpLockOn(){
        return this.upLock;
    }
    
    protected void setDownLock(boolean lock) {
        this.downLock = lock;
    }
    
    protected boolean isDownLockOn(){
        return this.downLock;
    }
    
    protected String getName(){
        return this.name;
    }
    
    public void resetFloorCount() {
        floorCount = 0;
    }

}
